#include <stdio.h>
#include <unistd.h>
#include "socklib.h"

#define LEN 100
#define HOST "127.0.1.1"

void talk_with_server(int fd);

int main()
{
    int sock_id = connect_to_server(HOST,1496);
    if (sock_id == -1){
        return -1;
    }

    talk_with_server(sock_id);

    close(sock_id);

    return 0;
}

void talk_with_server(int fd)
{
    char buf[LEN];
    int n;

    //n = read(fd,buf,LEN);
    //write(1,buf,n);
    n = recvMsg(fd, buf, LEN, 100);
    if (n < 0) {
        return;
    }
    printf("Recv:%s\n", buf);
    printf("Send:Thank you!\n");
    n = sendMsg(fd, "Thank you!", 100);
    if (n < 0) {
        return;
    }
    n = recvMsg(fd, buf, LEN, 1001);
    if (n < 0) {
        return;
    }
    printf("Recv:%s\n", buf);
}


